/*
  -----------------
  OOPC Object model
  -----------------
*/

/*
  base types
*/

/* object type (public) */
typedef union {
  struct _ooc_vtbl_object const* const  __vptr;
  struct _ooc_vtbl_object const*_CONST_ __iptr;
} t_object;

/* object virtual table type (private) */
struct _ooc_vtbl_object {
  struct _ooc_type_info const*_CONST_ info;
  size_t offset;
};

/* object class type */
struct _ooc_class_object {
  struct _ooc_vtbl_object const*const __vptr;
  t_object  (*const object) (void);
  void (*const _object)  (t_object *const);
  t_object* (*const alloc)  (void);
};

/* object RTTI (private) */
struct _ooc_type_info {
  char const*const name;
  struct _ooc_class_object const*_CONST_ class;
  t_object const*_CONST_ obj;
  struct _ooc_type_info const*_CONST_ super;
  size_t _CONST_ extraSuper;
  size_t _CONST_ extraOffset[_OBJECT_MAXSUPER_];
};

/*
  OBJECT types
*/

/* OBJECT type (public) */
typedef union {
  struct _ooc_vtbl_OBJECT const* const  __vptr;  /* vitual table access  */ 
  struct _ooc_vtbl_object const*_CONST_ __iptr;  /* info & offset access */

  struct { /* access to members */
    t_SUPER1 SUPER1; /* INHERIT_MEMBERS_OF(SUPER1) */
    t_SUPER2 SUPER2; /* INHERIT_MEMBERS_OF(SUPER2) */
    
    /* OBJECT members */

  } m;
} t_OBJECT;

/* OBJECT virtual table type (private) */
struct _ooc_vtbl_OBJECT {
  struct _ooc_vtbl_SUPER1 SUPER1; /* INHERIT_METHODS_OF(SUPER1) */
  struct _ooc_vtbl_SUPER2 SUPER2; /* INHERIT_METHODS_OF(SUPER2) */

  /* OBJECT methods */
};

/* OBJECT class type (private) */
struct _ooc_class_OBJECT {
  struct _ooc_vtbl_OBJECT const*const __vptr;
  t_OBJECT classMethod(OBJECT);      /* default constructor */
  void method(_OBJECT);              /* default destructor  */
  t_OBJECT*const classMethod(alloc); /* default allocator   */

  /* OBJECT class members */
};

/*
  object creation if new available
*/

t_OBJECT *obj = OBJECT.new(...);

/*
  object members
*/
  
/* access to data */
obj->m.datafield;
/* access to superclass sclass data */
obj->m.sclass.m.datafield;
/* access to supersuperclass ssclass data */
obj->m.sclass.m.ssclass.m.datafield;

/*
  object methods
*/

/* access to method */
obj->__vptr->method(obj);
/* access to superclass sclass method (I) bad */
obj->__vptr->sclass.method(&obj->m.sclass);
/* access to superclass sclass method (II) good */
(&obj->m.sclass)->__vptr->method(&obj->m.sclass);
/* access to supersuperclass ssclass method */
(&obj->m.sclass.m.ssclass)->__vptr->method(&obj->m.sclass.m.ssclass);

/*
  object infos
*/

/* object offset from base class */
obj->__iptr->offset;
/* object class name */
obj->__iptr->info->name;
/* object class address */
obj->__iptr->info->class;
/* object superclass info address */
obj->__iptr->info->super;
/* number of object extra superclasses */
obj->__iptr->info->extraSuper;
/* object superclasses offsets */
obj->__iptr->info->extraOffset[i];

/*
  EXAMPLES
*/

/* OBJECTS */

/* education --> object */
typedef union {
  struct _ooc_vtbl_education const*const __vptr;
  struct _ooc_vtbl_object    const*const __iptr;
  struct {
    t_object const private(_); /* base object */
    char const *diploma;
  } m;
} t_education;

/* person --> object */
typedef union {
  struct _ooc_vtbl_person const*const __vptr;
  struct _ooc_vtbl_object const*const __iptr;
  struct {
    t_object const private(_); /* base object */
    char const *name;
  } m;
} t_person;

/* employee --> person */
typedef union {
  struct _ooc_vtbl_employee const*const __vptr;
  struct _ooc_vtbl_object   const*const __iptr;
  struct {
    t_person person; /* derived object */
    char const *department;
  } m;
} t_employee;

/* manager --> employee
           --> education */
typedef union {
  struct _ooc_vtbl_manager const*const __vptr;
  struct _ooc_vtbl_object  const*const __iptr;
  struct {
    t_employee  employee;  /* derived object */
    t_education education; /* derived object */
    int level;
  } m;
} t_manager;
